﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls.Primitives;

namespace UBCon.Ribbon
{
    internal static class Utilities
    {
        internal static Popup BuildDropDownMenu(System.Windows.FrameworkElement elt)
        {
            System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();

            popup.PopupAnimation = System.Windows.Controls.Primitives.PopupAnimation.Fade;

            popup.AllowsTransparency = true;

            popup.StaysOpen = false;

            if (elt is UBCon.Ribbon.RibbonMenu)
            {
                UBCon.Ribbon.RibbonMenu ribbonMenu = elt as RibbonMenu;
                System.Windows.Data.BindingOperations.SetBinding
                    (
                        popup,
                        System.Windows.Controls.Primitives.Popup.IsOpenProperty,
                        new System.Windows.Data.Binding("IsOpen") { Source = ribbonMenu, Mode = System.Windows.Data.BindingMode.TwoWay }
                    );
                System.Windows.Data.BindingOperations.SetBinding
                    (
                        popup,
                        System.Windows.Controls.Primitives.Popup.PlacementProperty,
                        new System.Windows.Data.Binding("Placement") { Source = ribbonMenu, Mode = System.Windows.Data.BindingMode.TwoWay }
                    );

                popup.Child = ribbonMenu;
            }
            return popup;
        }

        internal static event EventHandler RibbonGalleryItemSelectedEvent;

        internal static void RaiseRibbonGalleryItemSelectedEvent(object sender)
        {
            if (RibbonGalleryItemSelectedEvent != null)
            {
                RibbonGalleryItemSelectedEvent(sender, EventArgs.Empty);
            }
        }
    }
}
